'''
Created on 2011-9-20

@author: Administrator
'''
import taskresult.base
import xml.dom.minidom
import logging


def Parser(xmlfile):
    resultlist = []
    try:
        doc = xml.dom.minidom.parse(xmlfile)
        for v in doc.getElementsByTagName('testcase'):
            ci  = taskresult.base.CaseInfo()
            ci.name = v.getAttribute('name')
            ci.runtime = v.getAttribute('time')
            ci.result = taskresult.base.PASS
            start_time = v.getAttribute('start_time')
            if start_time :
                ci.start_time = v.getAttribute('start_time')
            
            end_time = v.getAttribute('end_time')
            if end_time:
                ci.end_time = v.getAttribute('end_time')
            
            failure =  v.getElementsByTagName('failure')
            if failure :
                ci.result = taskresult.base.FAILURE
                ci.message = failure[0].getAttribute('message')
                
            error = v.getElementsByTagName('error')
            if error :
                ci.result = taskresult.base.FAILURE
                ci.message = error[0].getAttribute('message') 
            resultlist.append(ci)
    except Exception as e:
        logging.exception(e)
        
    return resultlist
